/*
 * Project Name: showtao
 * File Name: VehicleModelRepository.java
 * Interface Name: VehicleModelRepository
 *
 * Copyright 2014 showtao.com
 *
 * Licensed under the showtao.com
 *
 * http://showtao.com
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.showtao.front.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.showtao.front.domain.VehicleModel;

public interface VehicleModelRepository extends
		JpaRepository<VehicleModel, Long>,
		JpaSpecificationExecutor<VehicleModel> {

    @Query("select m from VehicleModel m "
    		+ " left join m.line "
    		+ " where m.id = :id")
    VehicleModel getOneJoinLine(@Param("id") Long id);
    
    @Query("select m from VehicleModel m "
            + " left join m.line "
            + " left join m.features "
            + " where m.id = :id")
    VehicleModel getOneJoinLineAndFeatures(@Param("id") Long id);
    
    @Query("select distinct m from VehicleModel m "
            + " left join m.line " 
            + " left join m.features")
    Page<VehicleModel> findAllJoinLineAndFeatures(Pageable pageable);
    
    @Query("select distinct m from VehicleModel m  "
    		+ " left join m.line "
    		+ " where m.name like :name")
    Page<VehicleModel> findByNameLike(@Param("name") String name, Pageable pageable);
    
    @Query("select distinct m from VehicleModel m  "
    		+ " left join m.line "
    		+ " where m.name like %:name%")
    List<VehicleModel> findByNameLike(@Param("name") String name);
}
